const path = require("path");
const { merge } = require("webpack-merge");
const CopyPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const common = require("./webpack.common.js");


const config = {
    mode: "production",
    devtool: false,
    plugins: [
        // 生产环境下将 public 目录下的静态资源拷贝至 output.path 目录下
        new CopyPlugin({
            patterns: [
                {
                    // 相对路径相对于 context，所以这里必须是 ./ 而不能是 ../
                    from: "./public",
                    globOptions: {
                        // 忽略 public 下的 index.html，即不拷贝 public/index.html
                        ignore: ["**/index.html", "**/.DS_Store"],
                    },
                },
            ],
        }),
    ],
    optimization: {
        usedExports: true,
        minimize: true,
        // `...` 保持对 js 代码的压缩，从而不覆盖掉 js 代码的压缩
        minimizer: [
            new TerserPlugin({
                extractComments: false,
            }),
        ],
    },
};

module.exports = merge(common, config);